﻿using Authorization.Center.Controllers;
using Authorization.Center.SqlServer;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using S.ReportForms.Domain.Dto;
using S.ReportForms.Read.API.Application.Command;
using static S.ReportForms.Read.API.Application.Command.BreadMatchingCountCommand;
using static S.ReportForms.Read.API.Application.Command.LambingStatisticsCommand;

namespace S.ReportForms.Read.API.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class LambingStatisticsController : BaseController
    {
        private readonly IMediator mediator;

        public LambingStatisticsController(MySqlDbContext _db, IMediator mediator) : base(_db)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 月产羔统计
        /// </summary>
        /// <returns></returns>
        [HttpGet("GetLambingDto")]
        public async Task<List<List<int>>> GetLambingDto(string? Year)
        {
            return await mediator.Send(new MonthLambingStatistics() { Year = Year });
        }
        /// <summary>
        /// 胎次动态统计
        /// </summary>
        /// <returns></returns>
        [HttpGet("GetLambingParity")]
        public async Task<List<string>> GetLambingParity()
        {
            return await mediator.Send(new ParityLambingStatistics() { });
        }
        /// <summary>
        /// 胎次动态统计
        /// </summary>
        /// <returns></returns>
        [HttpGet("GetLambingParityState")]
        public async Task<List<List<int>>> GetLambingParityState()
        {
            return await mediator.Send(new ParityStateLambingStatistics() { });
        }

        /// <summary>
        /// 产羔哺乳情况
        /// </summary>
        /// <param name="selectYear">统计的年份</param>
        /// <param name="indicators">指标</param>
        /// <returns></returns>
        [HttpGet("GetLambingLactationStatistics")]
        public async Task<List<LambingLactationStatisticsDto>> GetLambingLactationStatistics(int selectYear, int indicators)
        {
            if(selectYear==null || indicators==null || selectYear == 0 || indicators == 0)
            {
                return null;
            }
            return await mediator.Send(new LambingLactationStatistics()
            {
                SelectYear = selectYear,
                Indicators = indicators
            });
        }
        /// <summary>
        /// 产羔图表统计
        /// </summary>
        /// <returns></returns>
        [HttpGet("GetCountLambingStatices")]
        public async Task<List<LambingRursingDto>> GetCountLambingStatices(string? Year)
        {
            return await mediator.Send(new CountLambingStatices() {Year=Year });
        }
    }
}
